package com.health.controller;


import com.health.pojo.Product;
import com.health.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Value("${serverAddress.rabbitMQ}")
    private String rabbitMQ;
    /**
     * 测试读取配置
     */
    @RequestMapping("/view/findProductById3")
    public String findProductById3(Integer id){
        System.out.println("获取的商品id:"+id);
        return "获取的商品id:"+id;
    }
    /**
     * 测试读取配置
     */
    @RequestMapping("/showConfig")
    public String showConfig(){
        System.out.println("读取到的配置消息:"+rabbitMQ);
        return rabbitMQ;
    }

    //方法名可以相同,参数必须不同,映射地址必须不同
    @RequestMapping("/getProductById2")
    public Product getProductById2(Integer id, @RequestBody User user){

        System.out.println("查询到商品id:"+id);
        System.out.println("查询得到的user:"+user);
        Product product = new Product(id, "洗发液", 123D);
        return product;
    }


    @RequestMapping("/getProductById/{id}")
    public String getProductById(@PathVariable(value = "id") Integer id){
        System.out.println("查询到商品id:"+id);
        //模拟异常,熔断器触发
        int a=1/0;
        return "这是商品id>>:"+id;
    }
}
